<!DOCTYPE html>
<html>
  <head>
  <meta http-equiv="content-type" content="text/html; charset=utf-8">
  <meta content="width=device-width, initial-scale=1.0, maximum-scale=1.0, user-scalable=0" name="viewport">
  <meta name="description" content="tong.li&#39;s blog">
  <meta name="keyword" content="彤哥哥博客，95后技术爱好者,现就职于同程旅行/同程艺龙上海分公司，专注于互联网技术分享的平台。">
  
    <link rel="shortcut icon" href="/css/images/icon.png">
  
  <title>
    
      使用Jenkins进行持续集成 | 彤哥哥的博客
    
  </title>
  <link href="https://cdn.staticfile.org/font-awesome/4.7.0/css/font-awesome.min.css" rel="stylesheet">
  <link href="https://cdn.staticfile.org/nprogress/0.2.0/nprogress.min.css" rel="stylesheet">
  <link href="https://cdn.staticfile.org/highlight.js/9.12.0/styles/tomorrow-night.min.css" rel="stylesheet">
  
<link rel="stylesheet" href="/css/style.css">

  
  <script src="https://cdn.staticfile.org/jquery/3.2.1/jquery.min.js"></script>
  <script src="https://cdn.staticfile.org/geopattern/1.2.3/js/geopattern.min.js"></script>
  <script src="https://cdn.staticfile.org/nprogress/0.2.0/nprogress.min.js"></script>
  
    
<script src="/js/qrious.js"></script>

  
  
  
  
    <!-- MathJax support START -->
    <script type="text/x-mathjax-config">
      MathJax.Hub.Config({
        tex2jax: {
          inlineMath: [ ['$','$'], ["\\(","\\)"]  ],
          processEscapes: true,
          skipTags: ['script', 'noscript', 'style', 'textarea', 'pre', 'code']
        }
      });
    </script>

    <script type="text/x-mathjax-config">
      MathJax.Hub.Queue(function() {
        var all = MathJax.Hub.getAllJax(), i;
        for (i=0; i < all.length; i += 1) {
          all[i].SourceElement().parentNode.className += ' has-jax';
        }
      });
    </script>
    <script type="text/javascript" src="https://cdn.staticfile.org/mathjax/2.7.5/MathJax.js?config=TeX-AMS-MML_HTMLorMML"></script>
    <!-- MathJax support END -->
  


  
  
    
<script src="/js/local-search.js"></script>


<meta name="generator" content="Hexo 5.4.2"></head>
<div class="wechat-share">
  <img src="/css/images/logo.png" />
</div>
  <body>
    <header class="header fixed-header">
  <div class="header-container">
    <a class="home-link" href="/">
      <div class="logo"></div>
      <span>彤哥哥的博客</span>
    </a>
    <ul class="right-list">
      
        <li class="list-item">
          
            <a href="/" class="item-link">主页</a>
          
        </li>
      
        <li class="list-item">
          
            <a href="/series/" class="item-link">分类</a>
          
        </li>
      
        <li class="list-item">
          
            <a href="/tags/" class="item-link">标签</a>
          
        </li>
      
        <li class="list-item">
          
            <a href="/archives/" class="item-link">归档</a>
          
        </li>
      
        <li class="list-item">
          
            <a href="/project/" class="item-link">项目</a>
          
        </li>
      
        <li class="list-item">
          
            <a href="/about/" class="item-link">关于</a>
          
        </li>
      
      
        <li class="menu-item menu-item-search right-list">
    <a role="button" class="popup-trigger">
        <i class="fa fa-search fa-fw"></i>
    </a>
</li>
      
    </ul>
    <div class="menu">
      <span class="icon-bar"></span>
      <span class="icon-bar"></span>
      <span class="icon-bar"></span>
    </div>
    <div class="menu-mask">
      <ul class="menu-list">
        
          <li class="menu-item">
            
              <a href="/" class="menu-link">主页</a>
            
          </li>
        
          <li class="menu-item">
            
              <a href="/series/" class="menu-link">分类</a>
            
          </li>
        
          <li class="menu-item">
            
              <a href="/tags/" class="menu-link">标签</a>
            
          </li>
        
          <li class="menu-item">
            
              <a href="/archives/" class="menu-link">归档</a>
            
          </li>
        
          <li class="menu-item">
            
              <a href="/project/" class="menu-link">项目</a>
            
          </li>
        
          <li class="menu-item">
            
              <a href="/about/" class="menu-link">关于</a>
            
          </li>
        
      </ul>
    </div>
    
      <div class="search-pop-overlay">
    <div class="popup search-popup">
        <div class="search-header">
            <span class="search-icon">
                <i class="fa fa-search"></i>
            </span>
            <div class="search-input-container">
                <input autocomplete="off" autocapitalize="off"
                    placeholder="Please enter your keyword(s) to search." spellcheck="false"
                    type="search" class="search-input">
            </div>
            <span class="popup-btn-close">
                <i class="fa fa-times-circle"></i>
            </span>
        </div>
        <div id="search-result">
            <div id="no-result">
                <i class="fa fa-spinner fa-pulse fa-5x fa-fw"></i>
            </div>
        </div>
    </div>
</div>
    
  </div>
</header>

    <div id="article-banner">
  <h2>使用Jenkins进行持续集成</h2>
  <p class="post-date">2018-02-07</p>
  <div class="arrow-down">
    <a href="javascript:;"></a>
  </div>
</div>
<main class="app-body flex-box">
  <!-- Article START -->
  <article class="post-article">
    <section class="markdown-content"><p>Jenkins是一个开源软件项目，是基于Java开发的一种持续集成工具，用于监控持续重复的工作，旨在提供一个开放易用的软件平台，使软件的持续集成变成可能。</p>
<h2 id="安装Jenkins"><a href="#安装Jenkins" class="headerlink" title="安装Jenkins"></a>安装Jenkins</h2><p>首先我们去Jenkins官方网站下载最新的部署包(.war):<a target="_blank" rel="noopener" href="https://jenkins.io/download/">Jenkins</a>.<br>因为我是在Linux平台部署,需要注意的是Jenkins是基于Java构建的,所以我们必须安装好JDK系列的依赖才行.<br>Linux安装JDK时候先卸载本身自带的OpenJDK再进行安装,并配置好环境变量.JDK安装我不在累述,读者可自行百度.</p>
<figure class="highlight plaintext"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br></pre></td><td class="code"><pre><span class="line"># 通过wget方式下载Tomcat和Jenkins安装包</span><br><span class="line">[root@localhost bin]# wget http://mirrors.jenkins.io/war/latest/jenkins.war</span><br></pre></td></tr></table></figure>
<p>下载完成后会在当前目录出现jenkins.war,因为Jenkins内嵌Jetty服务器(也可以部署在Tomcat容器里),可以执行如下命令启动.</p>
<figure class="highlight plaintext"><table><tr><td class="gutter"><pre><span class="line">1</span><br></pre></td><td class="code"><pre><span class="line">[root@localhost bin]# java -jar jenkins.war</span><br></pre></td></tr></table></figure>
<p>执行以下命令,会打印出如下日志信息:</p>
<figure class="highlight plaintext"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br><span class="line">15</span><br><span class="line">16</span><br><span class="line">17</span><br><span class="line">18</span><br><span class="line">19</span><br><span class="line">20</span><br><span class="line">21</span><br><span class="line">22</span><br><span class="line">23</span><br><span class="line">24</span><br><span class="line">25</span><br><span class="line">26</span><br><span class="line">27</span><br><span class="line">28</span><br><span class="line">29</span><br><span class="line">30</span><br><span class="line">31</span><br><span class="line">32</span><br><span class="line">33</span><br><span class="line">34</span><br><span class="line">35</span><br><span class="line">36</span><br><span class="line">37</span><br><span class="line">38</span><br><span class="line">39</span><br><span class="line">40</span><br><span class="line">41</span><br><span class="line">42</span><br><span class="line">43</span><br><span class="line">44</span><br><span class="line">45</span><br><span class="line">46</span><br><span class="line">47</span><br><span class="line">48</span><br><span class="line">49</span><br><span class="line">50</span><br><span class="line">51</span><br><span class="line">52</span><br><span class="line">53</span><br><span class="line">54</span><br><span class="line">55</span><br><span class="line">56</span><br><span class="line">57</span><br><span class="line">58</span><br><span class="line">59</span><br><span class="line">60</span><br><span class="line">61</span><br><span class="line">62</span><br><span class="line">63</span><br><span class="line">64</span><br><span class="line">65</span><br><span class="line">66</span><br><span class="line">67</span><br><span class="line">68</span><br><span class="line">69</span><br><span class="line">70</span><br><span class="line">71</span><br><span class="line">72</span><br><span class="line">73</span><br><span class="line">74</span><br><span class="line">75</span><br><span class="line">76</span><br><span class="line">77</span><br><span class="line">78</span><br><span class="line">79</span><br><span class="line">80</span><br><span class="line">81</span><br><span class="line">82</span><br></pre></td><td class="code"><pre><span class="line">Running from: /usr/local/bin/jenkins.war</span><br><span class="line">webroot: $user.home/.jenkins</span><br><span class="line">二月 06, 2018 11:19:44 上午 Main deleteWinstoneTempContents</span><br><span class="line">警告: Failed to delete the temporary Winstone file /tmp/winstone/jenkins.war</span><br><span class="line">二月 06, 2018 11:19:44 上午 org.eclipse.jetty.util.log.Log initialized</span><br><span class="line">信息: Logging initialized @1303ms to org.eclipse.jetty.util.log.JavaUtilLog</span><br><span class="line">二月 06, 2018 11:19:44 上午 winstone.Logger logInternal</span><br><span class="line">信息: Beginning extraction from war file</span><br><span class="line">二月 06, 2018 11:19:47 上午 org.eclipse.jetty.server.handler.ContextHandler setContextPath</span><br><span class="line">警告: Empty contextPath</span><br><span class="line">二月 06, 2018 11:19:47 上午 org.eclipse.jetty.server.Server doStart</span><br><span class="line">信息: jetty-9.4.z-SNAPSHOT</span><br><span class="line">二月 06, 2018 11:19:47 上午 org.eclipse.jetty.webapp.StandardDescriptorProcessor visitServlet</span><br><span class="line">信息: NO JSP Support for /, did not find org.eclipse.jetty.jsp.JettyJspServlet</span><br><span class="line">二月 06, 2018 11:19:48 上午 org.eclipse.jetty.server.session.DefaultSessionIdManager doStart</span><br><span class="line">信息: DefaultSessionIdManager workerName=node0</span><br><span class="line">二月 06, 2018 11:19:48 上午 org.eclipse.jetty.server.session.DefaultSessionIdManager doStart</span><br><span class="line">信息: No SessionScavenger set, using defaults</span><br><span class="line">二月 06, 2018 11:19:48 上午 org.eclipse.jetty.server.session.HouseKeeper startScavenging</span><br><span class="line">信息: Scavenging every 600000ms</span><br><span class="line">Jenkins home directory: /root/.jenkins found at: $user.home/.jenkins</span><br><span class="line">二月 06, 2018 11:19:49 上午 org.eclipse.jetty.server.handler.ContextHandler doStart</span><br><span class="line">信息: Started w.@f9b7332&#123;/,file:///root/.jenkins/war/,AVAILABLE&#125;&#123;/root/.jenkins/war&#125;</span><br><span class="line">二月 06, 2018 11:19:49 上午 org.eclipse.jetty.server.AbstractConnector doStart</span><br><span class="line">信息: Started ServerConnector@2baa8d82&#123;HTTP/1.1,[http/1.1]&#125;&#123;0.0.0.0:8080&#125;</span><br><span class="line">二月 06, 2018 11:19:49 上午 org.eclipse.jetty.server.Server doStart</span><br><span class="line">信息: Started @6419ms</span><br><span class="line">二月 06, 2018 11:19:49 上午 winstone.Logger logInternal</span><br><span class="line">信息: Winstone Servlet Engine v4.0 running: controlPort=disabled</span><br><span class="line">二月 06, 2018 11:19:52 上午 jenkins.InitReactorRunner$1 onAttained</span><br><span class="line">信息: Started initialization</span><br><span class="line">二月 06, 2018 11:19:52 上午 jenkins.InitReactorRunner$1 onAttained</span><br><span class="line">信息: Listed all plugins</span><br><span class="line">二月 06, 2018 11:19:56 上午 jenkins.InitReactorRunner$1 onAttained</span><br><span class="line">信息: Prepared all plugins</span><br><span class="line">二月 06, 2018 11:19:56 上午 jenkins.InitReactorRunner$1 onAttained</span><br><span class="line">信息: Started all plugins</span><br><span class="line">二月 06, 2018 11:19:56 上午 jenkins.InitReactorRunner$1 onAttained</span><br><span class="line">信息: Augmented all extensions</span><br><span class="line">二月 06, 2018 11:19:59 上午 jenkins.InitReactorRunner$1 onAttained</span><br><span class="line">信息: Loaded all jobs</span><br><span class="line">二月 06, 2018 11:19:59 上午 hudson.eureka1-server.AsyncPeriodicWork$1 run</span><br><span class="line">信息: Started Download metadata</span><br><span class="line">二月 06, 2018 11:20:00 上午 jenkins.InitReactorRunner$1 onAttained</span><br><span class="line">信息: Completed initialization</span><br><span class="line">二月 06, 2018 11:20:02 上午 org.springframework.context.support.AbstractApplicationContext prepareRefresh</span><br><span class="line">信息: Refreshing org.springframework.web.context.support.StaticWebApplicationContext@fabd330: display name [Root WebApplicationContext]; startup date [Tue Feb 06 11:20:02 CST 2018]; root of context hierarchy</span><br><span class="line">二月 06, 2018 11:20:02 上午 org.springframework.context.support.AbstractApplicationContext obtainFreshBeanFactory</span><br><span class="line">信息: Bean factory for application context [org.springframework.web.context.support.StaticWebApplicationContext@fabd330]: org.springframework.beans.factory.support.DefaultListableBeanFactory@1452b2bc</span><br><span class="line">二月 06, 2018 11:20:02 上午 org.springframework.beans.factory.support.DefaultListableBeanFactory preInstantiateSingletons</span><br><span class="line">信息: Pre-instantiating singletons in org.springframework.beans.factory.support.DefaultListableBeanFactory@1452b2bc: defining beans [authenticationManager]; root of factory hierarchy</span><br><span class="line">二月 06, 2018 11:20:02 上午 org.springframework.context.support.AbstractApplicationContext prepareRefresh</span><br><span class="line">信息: Refreshing org.springframework.web.context.support.StaticWebApplicationContext@1a724d6e: display name [Root WebApplicationContext]; startup date [Tue Feb 06 11:20:02 CST 2018]; root of context hierarchy</span><br><span class="line">二月 06, 2018 11:20:02 上午 org.springframework.context.support.AbstractApplicationContext obtainFreshBeanFactory</span><br><span class="line">信息: Bean factory for application context [org.springframework.web.context.support.StaticWebApplicationContext@1a724d6e]: org.springframework.beans.factory.support.DefaultListableBeanFactory@7be61840</span><br><span class="line">二月 06, 2018 11:20:02 上午 org.springframework.beans.factory.support.DefaultListableBeanFactory preInstantiateSingletons</span><br><span class="line">信息: Pre-instantiating singletons in org.springframework.beans.factory.support.DefaultListableBeanFactory@7be61840: defining beans [filter,legacy]; root of factory hierarchy</span><br><span class="line">二月 06, 2018 11:20:03 上午 jenkins.install.SetupWizard init</span><br><span class="line">信息: </span><br><span class="line"></span><br><span class="line">*************************************************************</span><br><span class="line">*************************************************************</span><br><span class="line">*************************************************************</span><br><span class="line"></span><br><span class="line">Jenkins initial setup is required. An admin user has been created and a password generated.</span><br><span class="line">Please use the following password to proceed to installation:</span><br><span class="line"></span><br><span class="line">00caaea4ac874d4db11cb31c27e5c7ce</span><br><span class="line"></span><br><span class="line">This may also be found at: /root/.jenkins/secrets/initialAdminPassword</span><br><span class="line"></span><br><span class="line">*************************************************************</span><br><span class="line">*************************************************************</span><br><span class="line">*************************************************************</span><br><span class="line">二月 06, 2018 11:21:34 上午 hudson.eureka1-server.UpdateSite updateData</span><br><span class="line">信息: Obtained the latest update center data file for UpdateSource default</span><br><span class="line">二月 06, 2018 11:21:37 上午 hudson.eureka1-server.UpdateSite updateData</span><br><span class="line">信息: Obtained the latest update center data file for UpdateSource default</span><br><span class="line">二月 06, 2018 11:21:37 上午 hudson.WebAppMain$3 run</span><br><span class="line">信息: Jenkins is fully up and running</span><br><span class="line">二月 06, 2018 11:21:37 上午 hudson.eureka1-server.DownloadService$Downloadable load</span><br><span class="line">信息: Obtained the updated data file for hudson.tasks.Maven.MavenInstaller</span><br></pre></td></tr></table></figure>
<p>启动成功后,浏览器输入<a href="http://192.168.64.128:8080,则会进入以下界面">http://192.168.64.128:8080,则会进入以下界面</a>:<br><img src="https://ltyeamin.github.io/imgs/2020/07/20200731175132.png" alt="启动界面"><br>获取口令有好几种方式:</p>
<ol>
<li><p>上述启动日志里,这里口令为:00caaea4ac874d4db11cb31c27e5c7ce</p>
</li>
<li><p>/root/.jenkins/secrets/initialAdminPassword<br>复制口令填充进去并点击继续则进入下列界面:<br><img src="https://ltyeamin.github.io/imgs/2020/07/20200731175136.png" alt="安装界面"><br>这里我们选择安装推荐的默认安装方式,Jenkins就自动配置好了一些常用插件.最后,创建一个admin用户,完成安装.<br><img src="https://ltyeamin.github.io/imgs/2020/07/20200731175147.png" alt="首页"></p>
<h2 id="Jenkins配置"><a href="#Jenkins配置" class="headerlink" title="Jenkins配置"></a>Jenkins配置</h2><p>安装完成后,我们需要手动配置一些插件.如JDK,Maven,Git,Gradle等常用插件.</p>
</li>
<li><p>首页——&gt;系统管理—-&gt; 全局工具管理</p>
<figure class="highlight plaintext"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br></pre></td><td class="code"><pre><span class="line"># 下载maven-Dmaven.test.skip=true</span><br><span class="line">vi seting</span><br><span class="line">&lt;localRepository&gt;/usr/local/bin/apache-maven-3.5.2/repository&lt;/localRepository&gt;</span><br><span class="line">  &lt;mirrors&gt;</span><br><span class="line">     &lt;mirror&gt;</span><br><span class="line">        &lt;id&gt;nexus-aliyun&lt;/id&gt;</span><br><span class="line">        &lt;mirrorOf&gt;*&lt;/mirrorOf&gt;</span><br><span class="line">        &lt;name&gt;Nexus aliyun&lt;/name&gt;</span><br><span class="line">    &lt;url&gt;http://maven.aliyun.com/nexus/content/groups/public&lt;/url&gt;</span><br><span class="line">    &lt;/mirror&gt;</span><br><span class="line">  &lt;/mirrors&gt;</span><br></pre></td></tr></table></figure>
<p><img src="https://ltyeamin.github.io/imgs/2020/07/20200731175151.png" alt="配置全局的maven配置"><br><img src="https://ltyeamin.github.io/imgs/2020/07/20200731175155.png" alt="配置全局的maven"><br>Git我们选择默认安装,JDK手动去配置.</p>
</li>
<li><p>首页——&gt;系统管理—-&gt; 管理插件—–&gt;可选插件—-&gt;过滤——&gt;输入:Maven Integration plugin或者Git plugin—–&gt;选择性安装插件<br><img src="https://ltyeamin.github.io/imgs/2020/07/20200731175159.png" alt="插件配置"></p>
</li>
</ol>
<h1 id="构建自动化部署"><a href="#构建自动化部署" class="headerlink" title="构建自动化部署"></a>构建自动化部署</h1><p>Git项目地址: <a target="_blank" rel="noopener" href="https://gitee.com/ltalex/GitCeShi.git">https://gitee.com/ltalex/GitCeShi.git</a><br>在Jenkins首页选择新建任务,如下<br><img src="https://ltyeamin.github.io/imgs/2020/07/20200731175202.png" alt="部署1"><br><img src="https://ltyeamin.github.io/imgs/2020/07/20200731175208.png" alt="部署2"><br><img src="https://ltyeamin.github.io/imgs/2020/07/20200731175215.png" alt="部署3"><br><img src="https://ltyeamin.github.io/imgs/2020/07/20200731175223.png" alt="部署4"><br><img src="https://ltyeamin.github.io/imgs/2020/07/20200731175227.png" alt="部署5"><br><img src="https://ltyeamin.github.io/imgs/2020/07/20200731175231.png" alt="部署6"></p>
<p>以下配置表示maven构建结束后执行的脚本(Execute shell)</p>
<figure class="highlight plaintext"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br></pre></td><td class="code"><pre><span class="line">/usr/local/eureka/stop.sh</span><br><span class="line">/usr/local/eureka/replace.sh</span><br><span class="line"># 理论来说可以这样写nohup java -jar xxx.jar &amp;,但是这种配置在jenkis是无效的</span><br><span class="line">BUILD_ID=dontKillMe nohup /usr/local/eureka/startup.sh &amp;</span><br></pre></td></tr></table></figure>

<p>停止脚本</p>
<figure class="highlight plaintext"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br></pre></td><td class="code"><pre><span class="line"># 将应用停止</span><br><span class="line">#stop.sh</span><br><span class="line">#!/bin/bash</span><br><span class="line">echo &quot;Stopping SpringBoot Application&quot;</span><br><span class="line">pid=`ps -ef | grep eureka1-server.jar | grep -v grep | awk &#x27;&#123;print $2&#125;&#x27;`</span><br><span class="line">if [ -n &quot;$pid&quot; ]</span><br><span class="line">then</span><br><span class="line">   kill -9 $pid</span><br><span class="line">fi</span><br></pre></td></tr></table></figure>
<p>备份脚本</p>
<figure class="highlight plaintext"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br></pre></td><td class="code"><pre><span class="line">#replace.sh 用于将上次构建的结果备份，然后将新的构建结果移动到合适的位置</span><br><span class="line">#!/bin/bash</span><br><span class="line"># 先判断文件是否存在，如果存在，则备份</span><br><span class="line">file=&quot;/usr/local/eureka/eureka1-server.jar&quot;</span><br><span class="line">if [ -f &quot;$file&quot; ]</span><br><span class="line">then</span><br><span class="line">   mv /usr/local/eureka/eureka1-server.jar /usr/local/eureka/backup/eureka1-server.jar.`date +%Y%m%d%H%M%S`</span><br><span class="line">fi</span><br><span class="line">mv /root/.jenkins/workspace/Test/target/eureka1-server.jar /usr/local/eureka/eureka1-server.jar</span><br></pre></td></tr></table></figure>
<p>启动脚本</p>
<figure class="highlight plaintext"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br></pre></td><td class="code"><pre><span class="line"># startup.sh 启动项目</span><br><span class="line">#!/bin/sh</span><br><span class="line">echo &quot;授予当前用户权限&quot;</span><br><span class="line">chmod 777 /usr/local/eureka/eureka1-server.jar</span><br><span class="line">echo &quot;执行.....&quot;</span><br><span class="line">java -jar /usr/local/eureka/eureka1-server.jar</span><br></pre></td></tr></table></figure>
<p>点击立即构建,Console会出现如下信息:<br><img src="https://ltyeamin.github.io/imgs/2020/07/20200731175235.png" alt="部署7"><br><img src="https://ltyeamin.github.io/imgs/2020/07/20200731175239.png" alt="部署8"></p>
<p>部署成功后,访问<a target="_blank" rel="noopener" href="http://192.168.64.128:8099/,%E5%A6%82%E4%B8%8B%E5%9B%BE">http://192.168.64.128:8099/,如下图</a>:<br><img src="https://ltyeamin.github.io/imgs/2020/07/20200731175243.png" alt="成功1"><br><img src="https://ltyeamin.github.io/imgs/2020/07/20200731175246.png" alt="成功2"></p>
<h2 id="遇到的问题"><a href="#遇到的问题" class="headerlink" title="遇到的问题"></a>遇到的问题</h2><ol>
<li>在部署的时候会出现java -jar出现没有主清单属性的问题,那是因为项目中Pom文件没有配置SpringBoot插件,导致在jar包中MANIFEST.MF文件没有启动信息<figure class="highlight plaintext"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br></pre></td><td class="code"><pre><span class="line">java -jar eureka1-server.jar</span><br><span class="line">eureka1-server.jar中没有主清单属性</span><br></pre></td></tr></table></figure>
解决方案:<figure class="highlight plaintext"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br></pre></td><td class="code"><pre><span class="line">&lt;plugin&gt;</span><br><span class="line">	&lt;groupId&gt;org.springframework.boot&lt;/groupId&gt;</span><br><span class="line">	&lt;artifactId&gt;spring-boot-maven-plugin&lt;/artifactId&gt;</span><br><span class="line">	&lt;executions&gt;</span><br><span class="line">	    &lt;execution&gt;</span><br><span class="line">	        &lt;goals&gt;</span><br><span class="line">	            &lt;goal&gt;repackage&lt;/goal&gt;</span><br><span class="line">	        &lt;/goals&gt;</span><br><span class="line">	    &lt;/execution&gt;</span><br><span class="line">	&lt;/executions&gt;</span><br><span class="line">&lt;/plugin&gt;</span><br></pre></td></tr></table></figure></li>
<li>构建成功后的脚本,即Execute shell尽量执行远程的shell脚本,不要直接在里面启动项目,因为项目启动后会一直停留,Jenkins就是构建成功也不会停止当前项目的构建状态.</li>
<li>可以定制构建出发器,当我们希望push一些东西能够立马构建项目时,可在构建触发器中勾选Poll SCM日程表表填写表达式:* * * * * </li>
</ol>
</section>
    <!-- Tags START -->
    
      <div class="tags">
        <span>Tags:</span>
        
  <a href="/tags#Jenkins" >
    <span class="tag-code">Jenkins</span>
  </a>

      </div>
    
    <!-- Tags END -->
    <!-- NAV START -->
    
  <div class="nav-container">
    <!-- reverse left and right to put prev and next in a more logic postition -->
    
      <a class="nav-left" href="/2018/01/30/%E6%B5%85%E8%B0%88%E5%8C%BF%E5%90%8D%E5%87%BD%E6%95%B0,Lambda,%E9%97%AD%E5%8C%85(Closure)/">
        <span class="nav-arrow">← </span>
        
          浅谈匿名函数,Lambda和闭包(Closure)
        
      </a>
    
    
      <a class="nav-right" href="/2018/03/15/%E7%BA%BF%E7%A8%8B%E5%88%87%E6%8D%A2%E5%AF%BC%E8%87%B4ThreadLocal%E6%95%B0%E6%8D%AE%E4%B8%A2%E5%A4%B1%E5%88%86%E6%9E%90/">
        
          线程切换导致ThreadLocal数据丢失分析
        
        <span class="nav-arrow"> →</span>
      </a>
    
  </div>

    <!-- NAV END -->
    <!-- 打赏 START -->
    
      <div class="money-like">
        <div class="reward-btn">
          赏
          <span class="money-code">
            <span class="alipay-code">
              <div class="code-image"></div>
              <b>使用支付宝打赏</b>
            </span>
            <span class="wechat-code">
              <div class="code-image"></div>
              <b>使用微信打赏</b>
            </span>
          </span>
        </div>
        <p class="notice">若你觉得我的文章对你有帮助，欢迎点击上方按钮对我打赏</p>
      </div>
    
    <!-- 打赏 END -->
    <!-- 二维码 START -->
    
      <div class="qrcode">
        <canvas id="share-qrcode"></canvas>
        <p class="notice">扫描二维码，分享此文章</p>
      </div>
    
    <!-- 二维码 END -->
    
      <!-- Utterances START -->
      <div id="utterances"></div>
      <script src="https://utteranc.es/client.js"
        repo="ltyeamin/blogtalks"
        issue-term="pathname"
        theme="github-light"
        crossorigin="anonymous"
        async></script>    
      <!-- Utterances END -->
    
  </article>
  <!-- Article END -->
  <!-- Catalog START -->
  
    <aside class="catalog-container">
  <div class="toc-main">
    <strong class="toc-title">Catalog</strong>
    
      <ol class="toc-nav"><li class="toc-nav-item toc-nav-level-2"><a class="toc-nav-link" href="#%E5%AE%89%E8%A3%85Jenkins"><span class="toc-nav-text">安装Jenkins</span></a></li><li class="toc-nav-item toc-nav-level-2"><a class="toc-nav-link" href="#Jenkins%E9%85%8D%E7%BD%AE"><span class="toc-nav-text">Jenkins配置</span></a></li></ol></li><li class="toc-nav-item toc-nav-level-1"><a class="toc-nav-link" href="#%E6%9E%84%E5%BB%BA%E8%87%AA%E5%8A%A8%E5%8C%96%E9%83%A8%E7%BD%B2"><span class="toc-nav-text">构建自动化部署</span></a><ol class="toc-nav-child"><li class="toc-nav-item toc-nav-level-2"><a class="toc-nav-link" href="#%E9%81%87%E5%88%B0%E7%9A%84%E9%97%AE%E9%A2%98"><span class="toc-nav-text">遇到的问题</span></a></li></ol>
    
  </div>
</aside>
  
  <!-- Catalog END -->
</main>

<script>
  (function () {
    var url = 'http://example.com/2018/02/07/使用Jenkins进行持续集成/';
    var banner = ''
    if (banner !== '' && banner !== 'undefined' && banner !== 'null') {
      $('#article-banner').css({
        'background-image': 'url(' + banner + ')'
      })
    } else {
      $('#article-banner').geopattern(url)
    }
    $('.header').removeClass('fixed-header')

    // error image
    $(".markdown-content img").on('error', function() {
      $(this).attr('src', '/css/images/error_icon.png')
      $(this).css({
        'cursor': 'default'
      })
    })

    // zoom image
    $(".markdown-content img").on('click', function() {
      var src = $(this).attr('src')
      if (src !== '/css/images/error_icon.png') {
        var imageW = $(this).width()
        var imageH = $(this).height()

        var zoom = ($(window).width() * 0.95 / imageW).toFixed(2)
        zoom = zoom < 1 ? 1 : zoom
        zoom = zoom > 2 ? 2 : zoom
        var transY = (($(window).height() - imageH) / 2).toFixed(2)

        $('body').append('<div class="image-view-wrap"><div class="image-view-inner"><img src="'+ src +'" /></div></div>')
        $('.image-view-wrap').addClass('wrap-active')
        $('.image-view-wrap img').css({
          'width': `${imageW}`,
          'transform': `translate3d(0, ${transY}px, 0) scale3d(${zoom}, ${zoom}, 1)`
        })
        $('html').css('overflow', 'hidden')

        $('.image-view-wrap').on('click', function() {
          $(this).remove()
          $('html').attr('style', '')
        })
      }
    })
  })();
</script>


  <script>
    var qr = new QRious({
      element: document.getElementById('share-qrcode'),
      value: document.location.href
    });
  </script>






    <div class="scroll-top">
  <span class="arrow-icon"></span>
</div>
    <footer class="app-footer">
  <p class="copyright">
    &copy; 2024 | Proudly powered by <a href="https://hexo.io" target="_blank">Hexo</a>
    <br>
    Theme by <a target="_blank" rel="noopener" href="https://github.com/ltyeamin">tong.li</a>
  </p>
</footer>

<script>
  function async(u, c) {
    var d = document, t = 'script',
      o = d.createElement(t),
      s = d.getElementsByTagName(t)[0];
    o.src = u;
    if (c) { o.addEventListener('load', function (e) { c(null, e); }, false); }
    s.parentNode.insertBefore(o, s);
  }
</script>
<script>
  async("https://cdn.staticfile.org/fastclick/1.0.6/fastclick.min.js", function(){
    FastClick.attach(document.body);
  })
</script>

<script>
  var hasLine = 'true';
  async("https://cdn.staticfile.org/highlight.js/9.12.0/highlight.min.js", function(){
    $('figure pre').each(function(i, block) {
      var figure = $(this).parents('figure');
      if (hasLine === 'false') {
        figure.find('.gutter').hide();
      }
      hljs.configure({useBR: true});
      var lang = figure.attr('class').split(' ')[1] || 'code';
      var codeHtml = $(this).html();
      var codeTag = document.createElement('code');
      codeTag.className = lang;
      codeTag.innerHTML = codeHtml;
      $(this).attr('class', '').empty().html(codeTag);
      figure.attr('data-lang', lang.toUpperCase());
      hljs.highlightBlock(block);
    });
  })
</script>
<!-- Baidu Tongji -->



<script src='https://cdn.staticfile.org/mermaid/8.11.2/mermaid.min.js'></script>



<script src="/js/script.js"></script>


  </body>
</html>